package com.article.service.impl;

import com.article.common.PageParam;
import com.article.dao.IArticleDao;
import com.article.model.Article;
import com.article.service.IArticleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class ArticleServiceImpl implements IArticleService {
    @Resource
    private IArticleDao dao;

    /**
     * 列表查询
     * @param pageParam
     * @author lx
     * @return
     */
    @Override
    public PageParam queryAll (PageParam pageParam){
        pageParam.setData(this.dao.queryAll(pageParam));
        pageParam.setCount(pageParam.getData().size());
        pageParam.setCode(0);
        return pageParam;
    }

    /**
     * 根据id获取单条
     * @param id
     * @author lx
     * @return
     */
    @Override
    public Article getOne (Integer id){
        return dao.selectById(id);
    }

    /**
     * 新增
     * @param entity
     * @author lx
     * @return
     */
    @Override
    public boolean add (Article entity){
        return dao.insert(entity)>0;
    }

    /**
     * 修改
     * @param entity
     * @author lx
     * @return
     */
    @Override
    public boolean update (Article entity) {
        return dao.updateById(entity) > 0;
    }
    /**
     * 删除
     * @param id
     * @author lx
     * @return
     */
    @Override
    public boolean delete(Integer id){
        return dao.deleteById(id)>0;
    }

    /**
     * 批量删除
     * @param ids
     * @author lx
     * @return
     */
    @Override
    public boolean deleteByIds(Integer[] ids){
        for(Integer id:ids){
            dao.deleteById(id);
        }
        return true;
    }


}
